<template>
  <div class="page-wrap">
    <div class="page-title">CdsPassword 密码组件</div>
    <div class="page-sub-title">基本用法</div>
    <codeShow :code="code1">
      <el-form
        ref="ruleFormRef"
        :model="form"
        label-width="auto"
        style="width: 700px"
      >
        <CdsPassword
          v-model:password="form.password"
          v-model:confirmPassword="form.confirmPassword"
          required
          isAutomatically
        />
        <el-form-item>
          <el-button type="primary" @click="submitForm(ruleFormRef)">
            Create
          </el-button>
          <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
        </el-form-item>
      </el-form>
    </codeShow>

    <div class="page-sub-title">CdsPassword API</div>
    <el-table :data="tableData" style="margin-top: 20px; margin-bottom: 48px">
      <el-table-column
        label="属性名"
        align="left"
        width="150"
        prop="attr"
      ></el-table-column>
      <el-table-column
        label="说明"
        align="left"
        prop="illustrate"
      ></el-table-column>
      <el-table-column
        label="类型"
        align="left"
        width="150"
        prop="type"
      ></el-table-column>
      <el-table-column
        label="默认值"
        align="left"
        width="150"
        prop="default"
      ></el-table-column>
    </el-table>

    <div class="page-sub-title">注意事项</div>
    <div>校验需要放在el-form内使用</div>
    <div>正则需要符合new RegExp()创建正则的参数规则</div>
  </div>
</template>

<script setup> 
// import { CdsPassword } from 'cds-ui-business-components'
import {CdsPassword} from 'cds-ui-business-components'
import codeShow from '../../components/code.vue'
import { reactive, ref } from 'vue';
const ruleFormRef = ref();
const form = reactive({
  password: '',
  confirmPassword: ''
});
const submitForm = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
    } else {
      console.log('error submit!', fields)
    }
  })
};



const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
};


const tableData = ref([
  {
    'attr': 'v-model:password', 'illustrate': '密码', 'type': 'String', 'default': ''
  },
  {
    'attr': 'v-model:confirmPassword', 'illustrate': '确认密码', 'type': 'String', 'default': ''
  },
  {
    'attr': 'required', 'illustrate': '是否必填校验', 'type': 'Boolean', 'default': false
  },
  {
    'attr': 'isAutomatically', 'illustrate': '是否自动生成密码', 'type': 'Boolean', 'default': false
  },
  {
    'attr': 'regexPattern ', 'illustrate': '校验正则', 'type': 'String', 'default': '(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%&*~()-+=]+$)(?![0-9\\W_!@#$%^&*()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`()-+=]{8,30}$'
  },
  {
    'attr': 'regexFlags ', 'illustrate': '校验正则的标志', 'type': 'String', 'default': ''
  },
  {
    'attr': 'passwordMsg', 'illustrate': '密码的提示', 'type': 'String', 'default': '8-30个字符，且同时包含三项(大写字母、小写字母、数字、0~!@#S%A&*+=_..?/中的特殊字符)'
  },
])

const code1 = `
//template
    <el-form
      ref="ruleFormRef"
      :model="form"
      label-width="auto"
      style="width: 500px"
    >
      <CdsPassword
        v-model:password="form.password"
        v-model:confirmPassword="form.confirmPassword"
        required
        isAutomatically
      />
      <el-form-item>
        <el-button type="primary" @click="submitForm(ruleFormRef)">
          Create
        </el-button>
        <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
      </el-form-item>
    </el-form> 
//script
import CdsPassword from 'cds-ui-business-components/dist/es/cdsPassword'
const form = reactive({
  password: '',
  confirmPassword: ''
});
const submitForm = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
    } else {
      console.log('error submit!', fields)
    }
  })
};

const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
};
`;
</script> 
<style lang="scss" scoped>
</style>